//
//  LZGroupDetailViewController.m
//  laziz_Consumer
//
//  Created by xbnzd on 16/11/18.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZGroupDetailViewController.h"
#import "UIViewController+NavigationItemSetting.h"
#import "UIButton+TransitionEdgeInsets.h"
#import "LZFightGroupDetailOrderRulesCell.h"
#import "LZFightGroupDetailRulesOfUseCell.h"
#import "LZFightGroupDetailMealsTimeCell.h"
#import "LZVideoPublisherCell.h"
#import "LZJoinGroupDetialHeadCell.h"
#import "UITableView+FDTemplateLayoutCell.h"
#import "XBNTimeLimitCountDownCalculator.h"
#import "LZTimeLimitCountDownJudgeDataManager.h"
#import "LZGrouponPresenter.h"
#import "LZAlertView.h"
#import "LZGroupDetailModel.h"
#import "LZGrabCouponAndFightGroupsDetialModel.h"
#import "LZUserModel.h"
#import "LZGroupUser.h"
#import "TShareView.h"
#import "TShareEventHandler.h"
#import "LZDateFormatterManager.h"


static NSString *kOrderRulesCell = @"orderRulesCell";
static NSString *kRulesOfUseCell = @"rulesOfUseCell";
static NSString *kMealsTimeCell  = @"mealsTimeCell";
static NSString *kPublisherCell  = @"publisherCell";

typedef NS_ENUM(NSInteger ,JoinGrouponStatus) {
    JoinGrouponStatus_Hidden,   // 按钮隐藏状态
    JoinGrouponStatus_Join,     // 如果当前用户不是开团用户,并且没参加
    JoinGrouponStatus_Cancel,   // 如果当前用户是开团用户,并且当前团没人
    JoinGrouponStatus_Quit      // 如果当前用户不是开团用户,并且已经参加了
};

@interface LZGroupDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *bottomButton;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewToViewBottomConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewToButtonConstraint;

@property (nonatomic, assign) BOOL isTimeEnd;   // 时间是否结束了
@property (nonatomic, strong) LZGroupDetailModel *model;
@property (nonatomic, strong) LZJoinGroupDetialHeadCell *headCell;
@property (nonatomic, assign) JoinGrouponStatus status;

@property (strong, nonatomic) XBNTimeLimitCountDownCalculator *timeCountDownCalculator;

@property (nonatomic, strong) TShareView * shareView;

@end

@implementation LZGroupDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.umLogPageViewName = @"团购详情页面";
    
    self.title = LZLocalizedString(@"group_details", nil);
    if (self.isUserCenter) {
        [self configNavigationBarRightShareButton];
    }
    self.bottomButton.hidden = YES;
    [self registerCell];
    [self requestGrouponDetailInfo];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - request

// 团购信息
- (void)requestGrouponDetailInfo {
    WS(weakSelf)
    [LZGrouponPresenter getVideoGroupDetailWithGroupID:self.grouponId ResultSuccess:^(id result,NSNumber *timestamp) {
        weakSelf.model = (LZGroupDetailModel*)result;
        [weakSelf refreshButton];
        weakSelf.headCell.model = (LZGroupDetailModel*)result;
        [weakSelf.tableView reloadData];
        [weakSelf createLimitCountDownCalculator:[timestamp longLongValue]/1000];
    } ResultFailed:^(NSString *remind) {
        
    }];
}

// 参团
- (void)requestJoinGroupon {
    WS(weakSelf)
    [LZGrouponPresenter joinGrouponWithGroupID:self.model.groupId SellerID:self.model.sellerId PromotionID:self.model.promotionId GrouponCount:self.model.salesPromotion.grouponCount ResultSuccess:^(id result) {
        
        if ([result[@"statusCode"] integerValue] == kCodeSuccesss) {
            
            // 先更新model
            weakSelf.model.peopleCount = [NSString stringWithFormat:@"%ld",[weakSelf.model.peopleCount integerValue]+1];
            weakSelf.model.isGroupon = YES;
            [weakSelf refreshButton];
            
            // 剩余人数
            NSString *residue = [NSString stringWithFormat:@"%ld",[weakSelf.model.salesPromotion.grouponCount integerValue] - [weakSelf.model.peopleCount integerValue]];
            if ([residue integerValue] == 0) {
                // 如果正好是最后一个人
                LZAlertView *alert = [[LZAlertView alloc] initWithContent:[NSString stringWithFormat:LZLocalizedString(@"group_join_success", nil),residue] andImage:nil cancelButtonTitle:nil otherButtonTitles:LZLocalizedString(@"confirm", nil),nil];
                [alert show];
                alert.clickButtonIndexBlock = ^(NSInteger index) {
                    [weakSelf.navigationController popToRootViewControllerAnimated:YES];
                };
            }
            else {
                // 弹出提示框
                LZAlertView *alert = [[LZAlertView alloc] initWithContent:[NSString stringWithFormat:LZLocalizedString(@"group_join_success_remind", nil),residue] andImage:nil cancelButtonTitle:LZLocalizedString(@"group_later", nil) otherButtonTitles:LZLocalizedString(@"group_invite", nil),nil];
                [alert show];
                
                alert.clickButtonIndexBlock = ^(NSInteger index) {
                    if (index == 0) {
                        [weakSelf.navigationController popToRootViewControllerAnimated:YES];
                    }
                    else {
                        [weakSelf openShare];
                    }
                };
            }
        }else{
            NSString *str = result[@"statusCode"];
            [weakSelf dealErrorStatus:str];
        }
    } ResultFailed:^(NSString *remind) {
        
    }];
}

// 退团 ----------- 指参团人
- (void)requestQuitGroupon {
    WS(weakSelf)
    [LZGrouponPresenter quitGrouponWithDisCountNo:self.disCountNo GroupID:self.model.groupId PromotionID:self.model.promotionId ResultSuccess:^(id result) {
        if ([result[@"statusCode"] integerValue] == kCodeSuccesss) {
            if (weakSelf.cancelOrQuitGrouponBlock) {
                weakSelf.cancelOrQuitGrouponBlock(weakSelf.indexPath);
            }
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
        else{
            NSString *str = result[@"statusCode"];
            [weakSelf dealErrorStatus:str];
        }
    } ResultFailed:^(NSString *remind) {
        
    }];
}

// 取消团 ----------- 指开团人
- (void)requestCancelGroupon {
    WS(weakSelf)
    [LZGrouponPresenter cancelGrouponWithDisCountNo:self.disCountNo GroupID:self.model.groupId ResultSuccess:^(id result) {
        if ([result[@"statusCode"] integerValue] == kCodeSuccesss) {
            if (weakSelf.cancelOrQuitGrouponBlock) {
                weakSelf.cancelOrQuitGrouponBlock(weakSelf.indexPath);
            }
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
        else{
            NSString *str = result[@"statusCode"];
            [weakSelf dealErrorStatus:str];
        }
    } ResultFailed:^(NSString *remind) {
        
    }];
}

- (void)dealErrorStatus:(NSString*)status {
    if ((!status || (NSNull *)status == [NSNull null]))  {
        return;
    }
    
    if (![LZBasePresenter checkAuthorStatus:status]) {
        return;
    }
    
    if ([status isEqualToString:@"0500022"]) {
        DLog(@"团购人数已经满");
        self.model.peopleCount = self.model.salesPromotion.grouponCount;
        [self refreshButton];
        [self showClosedAlert:LZLocalizedString(@"group_closed_remind", nil)];
    }
    else if ([status isEqualToString:@"0500025"]) {
        DLog(@"用户已参加过该优惠");
        self.model.isGroupon = YES;
        [self refreshButton];
        
        LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"group_joined_remind", nil) andImage:nil cancelButtonTitle:nil otherButtonTitles:LZLocalizedString(@"confirm", nil),nil];
        [alert show];
        
        WS(weakSelf)
        alert.clickButtonIndexBlock = ^(NSInteger index) {
            [weakSelf.navigationController popToRootViewControllerAnimated:YES];
        };
    }
    else if ([status isEqualToString:@"0500027"]) {
        DLog(@"优惠活动已经结束");
        self.isTimeEnd = YES;
        [self showClosedAlert:LZLocalizedString(@"group_detail_complete_cannot_cancel_remind", nil)];
    }
    else if ([status isEqualToString:@"0500028"]) {
        DLog(@"已成团，不能再退出");
        [self showClosedAlert:LZLocalizedString(@"group_detail_complete_cannot_quit_remind", nil)];
    }
    else if ([status isEqualToString:@"0500029"]) {
        DLog(@"优惠活动已结束，不能再退出");
        self.isTimeEnd = YES;
        [self showClosedAlert:LZLocalizedString(@"group_detail_closed_cannot_quit_remind", nil)];
    }
    else if ([status isEqualToString:@"0500030"]) {
        DLog(@"已有其他用户加入，不能删除团购");
        [self showClosedAlert:LZLocalizedString(@"group_detail_cannot_cancel_remind", nil)];
    }
}

#pragma mark -
#pragma mark publick methor

- (void) createLimitCountDownCalculator:(NSTimeInterval)nowTime {
    if (!self.isUserCenter || self.timeCountDownCalculator) {
        return;
    }

    // ******************** 创建计时器 ********************
    
    if (self.model.salesPromotion.grouponEndTime/1000 <= nowTime) {
        [LZTimeLimitCountDownJudgeDataManager configLimitedLabel:self.headCell.timeDownLabel withReamin:0 andDayUnit:@"d " HourUnit:@"h " andMinuteUnit:@"m " andSecUnit:[NSString stringWithFormat:@"s %@",LZLocalizedString(@"group_left", nil)] andIsChangeUintColor:YES andDayUnitColor:UIColorFromRGB(0x999999, 1) HourUnitColor:UIColorFromRGB(0x999999, 1) andMinUnitColor:UIColorFromRGB(0x999999, 1) andSecUnitColor:UIColorFromRGB(0x999999, 1)];
    }
    else {
        self.timeCountDownCalculator = [XBNTimeLimitCountDownCalculator new];
        
        // 取出服务器时间
        self.timeCountDownCalculator.remainTimeInterval = self.model.salesPromotion.grouponEndTime/1000 - nowTime;
        
        [self startCountDownReamin:self.timeCountDownCalculator];
        
        [self.timeCountDownCalculator timeLimitCountDownResume];
    }
}

-(void)startCountDownReamin:(XBNTimeLimitCountDownCalculator*)limitCountDownCalculator {
    
    WS(weakSelf)
    [limitCountDownCalculator addProcessBlock:^(NSTimeInterval remain) {
        if (remain<=0) {
            weakSelf.isTimeEnd = YES;
            [weakSelf timeEndRefreshView];
            [LZTimeLimitCountDownJudgeDataManager configLimitedLabel:weakSelf.headCell.timeDownLabel withReamin:0 andDayUnit:@"d " HourUnit:@"h " andMinuteUnit:@"m " andSecUnit:[NSString stringWithFormat:@"s %@",LZLocalizedString(@"group_left", nil)] andIsChangeUintColor:YES andDayUnitColor:UIColorFromRGB(0x999999, 1) HourUnitColor:UIColorFromRGB(0x999999, 1) andMinUnitColor:UIColorFromRGB(0x999999, 1) andSecUnitColor:UIColorFromRGB(0x999999, 1)];
            
        }
        else {
            [LZTimeLimitCountDownJudgeDataManager configLimitedLabel:weakSelf.headCell.timeDownLabel withReamin:remain andDayUnit:@"d " HourUnit:@"h " andMinuteUnit:@"m " andSecUnit:[NSString stringWithFormat:@"s %@",LZLocalizedString(@"group_left", nil)] andIsChangeUintColor:YES andDayUnitColor:UIColorFromRGB(0x999999, 1) HourUnitColor:UIColorFromRGB(0x999999, 1) andMinUnitColor:UIColorFromRGB(0x999999, 1) andSecUnitColor:UIColorFromRGB(0x999999, 1)];
        }
        
    } cancelBlock:^{
        
    }];
}

- (void)timeEndRefreshView {
    self.bottomButton.hidden = YES;
    self.tableViewToViewBottomConstraint.priority = 999;
    self.tableViewToButtonConstraint.priority = 250;
    [self showClosedAlert:LZLocalizedString(@"group_closed_remind", nil)];
}

#pragma mark private methor

- (void)configNavigationBarRightShareButton {
    UIButton *nav_right_share = [UIButton buttonWithType:UIButtonTypeCustom];
    nav_right_share.frame = CGRectMake(0, 0, 40, 40);
    [nav_right_share addTarget:self action:@selector(navbarShareButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    UIImage *image_share = [UIImage imageNamed:@"share_icon"];
    [nav_right_share setImage:image_share forState:UIControlStateNormal];
    [nav_right_share setNormalImageEdgeInsets:UIEdgeInsetsMake(0, CGRectGetWidth(nav_right_share.bounds)-image_share.size.width, 0, 0)];
    [self navigationItemSetting:@[nav_right_share] type:NAVIGATIONITEMSETTING_RIGHT];
}

- (void)navbarShareButtonClickAction:(UIButton*)sender {
    if (self.model == nil) {
        return;
    }
    [self openShare];
}

- (void)openShare {
    WS(weakSelf)
    [self.shareView shareViewOpen];
    self.shareView.shareViewButtonActionBlock = ^(TSHAREVIEW_BUTTON_TYPE type){
        [weakSelf shareAction:type];
    };
    self.shareView.dismissViewBlock = ^() {
        if (weakSelf) {
            if (!weakSelf.isUserCenter) {
                [weakSelf.navigationController popToRootViewControllerAnimated:YES];
            }
        }
    };
}

- (void)shareAction:(NSInteger)type {
    /* 参团邀请 */
    SSDKPlatformType sharePlatformType = SSDKPlatformTypeUnknown;
    
    switch (type) {
        case 0:
            sharePlatformType = SSDKPlatformTypeSMS;
            break;
        case 1:
            sharePlatformType = SSDKPlatformTypeMail;
            break;
        case 2:
            sharePlatformType = SSDKPlatformTypeFacebook;
            break;
        case 3:
            sharePlatformType = SSDKPlatformTypeTwitter;
            break;
    }
    
    WS(weakSelf)
    [TShareEventHandler shareWithShareURL:nil
                            shareImageUrl:@[[NSString stringWithFormat:@"%@%@",APIBaseImageUrl,self.model.salesPromotion.videoPhoto]]
                               shareTitle:LZLocalizedString(@"share_join_group_invite_title", nil)
                                shareText:[NSString stringWithFormat:LZLocalizedString(@"share_join_group_invite_content", nil),self.model.salesPromotion.grouponName]
                                shareType:sharePlatformType
                                  topView:nil
     stateBlock:^(SSDKResponseState state) {
         DLog(@"%ld",state);
         if (weakSelf) {
             if (!weakSelf.isUserCenter) {
                 [weakSelf.navigationController popToRootViewControllerAnimated:YES];
             }
         }
     }];
    
    [self.shareView shareViewClose];
}

- (void)refreshButton {
    if (self.isTimeEnd == YES) {
        return;
    }
    if ([self.model.userId isEqualToString:[LZUserModel Instance].userId]) {
        // 如果当前用户是开团用户
        if ([self.model.peopleCount integerValue] == 1) {
            // 如果当前团没人
            self.status = JoinGrouponStatus_Cancel;
            self.bottomButton.hidden = NO;
            [self.bottomButton setTitle:LZLocalizedString(@"cancel_capital", nil) forState:UIControlStateNormal];
        }
        else {
            self.bottomButton.hidden = YES;
            self.tableViewToViewBottomConstraint.priority = 999;
            self.tableViewToButtonConstraint.priority = 250;
        }
    }
    else {
        // 如果当前用户不是开团用户
        
        if ([self.model.peopleCount integerValue] == [self.model.salesPromotion.grouponCount integerValue]) {
            // 如果当前团已满
            self.bottomButton.hidden = YES;
            self.tableViewToViewBottomConstraint.priority = 999;
            self.tableViewToButtonConstraint.priority = 250;
        }
        else {
            // 如果当前团没满
            self.bottomButton.hidden = NO;

            if (self.model.isGroupon) {
                // 如果已经参加了
                self.status = JoinGrouponStatus_Quit;
                [self.bottomButton setTitle:LZLocalizedString(@"mine_coupons_quit_big", nil) forState:UIControlStateNormal];
            }
            else {
                // 如果没参加
                self.status = JoinGrouponStatus_Join;
                [self.bottomButton setTitle:LZLocalizedString(@"group_join_big", nil) forState:UIControlStateNormal];
            }
        }
    }
}

- (IBAction)joinGroupBtnAction:(id)sender {
    if (self.isTimeEnd) {
        // 如果时间已经结束了
        [self showClosedAlert:LZLocalizedString(@"group_closed_remind", nil)];
        return;
    }
    else {
        if (self.status == JoinGrouponStatus_Join) {
            // 参团
            [self requestJoinGroupon];
        }
        else if (self.status == JoinGrouponStatus_Cancel) {
            // 取消团
            LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"mine_coupons_cancelgroupon_remind", nil) andImage:nil cancelButtonTitle:LZLocalizedString(@"cancel", nil) otherButtonTitles:LZLocalizedString(@"confirm", nil),nil];
            [alert show];
            
            WS(weakSelf)
            alert.clickButtonIndexBlock = ^(NSInteger index) {
                if (index == 1) {
                    [weakSelf requestCancelGroupon];
                }
            };
        }
        else if (self.status == JoinGrouponStatus_Quit) {
            // 退团
            LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"mine_coupons_quitgroupon_remind", nil) andImage:nil cancelButtonTitle:LZLocalizedString(@"cancel", nil) otherButtonTitles:LZLocalizedString(@"confirm", nil),nil];
            [alert show];
            
            WS(weakSelf)
            alert.clickButtonIndexBlock = ^(NSInteger index) {
                if (index == 1) {
                    [weakSelf requestQuitGroupon];
                }
            };
            
        }
    }
}


- (void)registerCell
{
    self.headCell = [[[NSBundle mainBundle] loadNibNamed:@"LZJoinGroupDetialHeadCell" owner:self options:nil] firstObject];
   
    [self.tableView registerNib:[UINib nibWithNibName:@"LZFightGroupDetailOrderRulesCell" bundle:nil] forCellReuseIdentifier:kOrderRulesCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZFightGroupDetailRulesOfUseCell" bundle:nil] forCellReuseIdentifier:kRulesOfUseCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZFightGroupDetailMealsTimeCell" bundle:nil] forCellReuseIdentifier:kMealsTimeCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZVideoPublisherCell" bundle:nil] forCellReuseIdentifier:kPublisherCell];
    
}

#pragma mark - 弹团购关闭的Alert

-(void)showClosedAlert:(NSString*)aString {
    
    LZAlertView *alert = [[LZAlertView alloc] initWithContent:aString andImage:nil cancelButtonTitle:nil otherButtonTitles:LZLocalizedString(@"confirm", nil),nil];
    
    [alert show];
    
    WS(weakSelf)
    alert.clickButtonIndexBlock = ^(NSInteger index) {
        //        NSLog(@"恩，确实点击了第%ld个按钮",(long)index);
        if (weakSelf.isUserCenter) {
            // 如果是用户中心进来的
            if (weakSelf.cancelOrQuitGrouponBlock) {
                weakSelf.cancelOrQuitGrouponBlock(weakSelf.indexPath);
            }
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
        else {
            // 如果是参团列表进来的
            if (weakSelf.isTimeEnd) {
                [weakSelf.navigationController popToRootViewControllerAnimated:YES];
            }
            else {
                if (weakSelf.fullUpBlock) {
                    weakSelf.fullUpBlock(weakSelf.indexPath);
                }
                [weakSelf.navigationController popViewControllerAnimated:YES];
            }
        }
    };
}

#pragma mark -
#pragma mark  tableview delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (self.model == nil) {
        return 0;
    }
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }
    
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return 10;
    }
    
    return  0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [self creatSectionFootView];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return self.headCell.intrinsicContentSize.height;
    }else{
       WS(weakSelf)
        switch (indexPath.row) {
            case 0:
                return [tableView fd_heightForCellWithIdentifier:kOrderRulesCell configuration:^(id cell) {
                    LZFightGroupDetailOrderRulesCell *cellTemp = (LZFightGroupDetailOrderRulesCell *)cell;
                    [cellTemp loadMembersNum:weakSelf.model.salesPromotion.grouponCount FinishedTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:weakSelf.model.salesPromotion.grouponEndTime]];
                    
                }];
                break;
            case 1:
                return [tableView fd_heightForCellWithIdentifier:kRulesOfUseCell configuration:^(id cell) {
                    LZFightGroupDetailRulesOfUseCell *cellTemp = (LZFightGroupDetailRulesOfUseCell *)cell;
                    [cellTemp loatGrouponName:weakSelf.model.salesPromotion.grouponName RulesContent:weakSelf.model.salesPromotion.grouponRemindRule ExpirationTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:weakSelf.model.salesPromotion.grouponDeadline]];
                }];
                break;
            case 2:
                return [tableView fd_heightForCellWithIdentifier:kMealsTimeCell configuration:^(id cell) {
                    LZFightGroupDetailMealsTimeCell *cellTemp = (LZFightGroupDetailMealsTimeCell *)cell;
                    NSString *everyDayValid = [weakSelf.model.salesPromotion getGroupEverydayValid];
                    [cellTemp loadValidExcept:weakSelf.model.salesPromotion.grouponExceptTime EverydayValid:everyDayValid otherContent:weakSelf.model.salesPromotion.grouponRemindAppoint];
                }];
                break;
            case 3:
                return [tableView fd_heightForCellWithIdentifier:kPublisherCell configuration:^(id cell) {
                    LZVideoPublisherCell *cellTemp = (LZVideoPublisherCell *)cell;
                    [cellTemp loadPublisherName:weakSelf.model.salesPromotion.restaurantName];
                }];
                break;
                
            default:
                break;

        }
    
   }
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return self.headCell;
        
    }else{
        switch (indexPath.row) {
           case 0:{
               LZFightGroupDetailOrderRulesCell *cell = [tableView dequeueReusableCellWithIdentifier:kOrderRulesCell];
               [cell loadMembersNum:self.model.salesPromotion.grouponCount FinishedTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.model.salesPromotion.grouponEndTime]];
                return cell;
            }
                
                break;
            case 1:{
                LZFightGroupDetailRulesOfUseCell *cell = [tableView dequeueReusableCellWithIdentifier:kRulesOfUseCell];
                [cell loatGrouponName:self.model.salesPromotion.grouponName RulesContent:self.model.salesPromotion.grouponRemindRule ExpirationTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.model.salesPromotion.grouponDeadline]];
                return cell;
            }
                
                break;
            case 2:{
                LZFightGroupDetailMealsTimeCell *cell = [tableView dequeueReusableCellWithIdentifier:kMealsTimeCell];
                NSString *everyDayValid = [self.model.salesPromotion getGroupEverydayValid];
                [cell loadValidExcept:self.model.salesPromotion.grouponExceptTime EverydayValid:everyDayValid otherContent:self.model.salesPromotion.grouponRemindAppoint];
                return cell;
            }
                
                break;
            case 3:{
                LZVideoPublisherCell *cell = [tableView dequeueReusableCellWithIdentifier:kPublisherCell];
                [cell loadPublisherName:self.model.salesPromotion.restaurantName];
                return cell;
            }
                
                break;
                
            default:
                break;
        }

    }
    
    return nil;
}
#pragma mark -
#pragma mark create
- (UIView *)creatSectionFootView
{
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
    v.backgroundColor = UIColorFromRGB(0xf0f0f0, 1);
    
    return v;
    
}

- (TShareView *)shareView {
    
    if (_shareView == nil) {
        _shareView = [[TShareView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    }
    
    return _shareView;
}


@end
